import Vue from 'vue'
import Router from 'vue-router'
import home from '../views/Home.vue'
import welcome from '../views/welcome/Welcome.vue'

Vue.use(Router)

let router = new Router({
    routes: [
        {
            path: '/Login',
            name: 'Login',
            component: function () {
                return import('../views/Login.vue')
            }
        },
        {
            path: '/Register',
            name: 'Register',
            component: function () {
                return import('../views/Register.vue')
            }
        },
        {
            path: '/',
            name: 'Home',
            component: home,
            redirect: {
                path: '/welcome'
            },
            children: [{
                name: 'welcome',
                path: '/welcome',
                component: welcome
            },
            {
                path: '/Asset',
                name: 'Asset',
                component: function () {
                    return import('../views/Asset/Asset.vue')
                }
            },
            {
                path: '/Statistics',
                name: 'Statistics',
                component: function () {
                    return import('../views/Statistics/Statistics.vue')
                }
            },
            {
                path: '/Check',
                name: 'Check',
                component: function () {
                    return import('../views/Check/Check.vue')
                }
            },
            {
                path: '/Board',
                name: 'Board',
                component: function () {
                    return import('../views/Board/Board.vue')
                }
            },
            ]
        },
        {
            path: '/Notice',
            name: 'Notice',
            component: function () {
                return import('../views/Notice/Notice.vue')
            }
        },
    ]
})
//注册一个全局守卫,作用是在路由跳转前,对路由进行判断,防止未登录的用户跳转到其他需要登录的页面去
/* router.beforeEach((to, from, next) => {
    let token = localStorage.getItem('mytoken')
    //如果登录,放行
    if (token) {
        next()
    } else {
        //如果没有登录.访问非登录页面,则跳转到登录页面
        if (to.path != '/') {
            next({
                path: '/'
            })
        } else {
            //如果没有登录,但访问的是登录页面,直接进入
            next()
        }
    }
}) */

export default router